﻿using SQLServerDialog.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SQLServerDialog
{
    internal class SQLServerFolderFileBrowser
    {

        private BrowserDAL browser;
        public SQLServerFolderFileBrowser(string server, string user, string password)
        {
            browser = new BrowserDAL(server,user,password);
        }


        internal List<string> GetDrives()
        {
            return browser.GetFixedDrives();
        }

        internal List<string> GetSubFolders(string parentFolder,bool skipDotPrefixFolder)
        {
            if(skipDotPrefixFolder)
                return browser.GetSubFolders(parentFolder).Where(folderName => !folderName.StartsWith(".") && !folderName.StartsWith("$")).ToList();
            else
                return browser.GetSubFolders(parentFolder);
        }

        internal List<string> GetFiles(string parentFolder, bool skipDotPrefixFiles, string filter)
        {
            string[] fileExtensions = filter.Split(',');
            if (skipDotPrefixFiles)
                return browser.GetFiles(parentFolder, fileExtensions).Where(fileName => !fileName.StartsWith(".")).ToList();
            else
                return browser.GetFiles(parentFolder, fileExtensions);
        }
    }
}
